/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2017 All Rights Reserved.
 */
package com.fulihui.integralbusiness.handler;

import com.fulihui.integral.core.enums.ISAccountType;
import com.fulihui.integral.core.enums.ISChannelType;
import com.fulihui.integral.core.request.RewardPointsReq;
import com.fulihui.integral.core.result.ISUserBehaviorResult;
import com.fulihui.integralbusiness.constants.IntegralBusinessFlags;
import org.near.servicesupport.util.ServiceResultUtil;
import org.near.toolkit.common.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.UUID;

/**
 * @author: Levon
 * @version: v 0.1 2017-06-14 16:42
 */
@Component("shareIntegralBusinessHandler")
public class ShareIntegralBusinessHandler extends AbstractIntegralBusinessHandler{

    private transient final Logger log = LoggerFactory.getLogger(getClass());

    @Override
    public void handle(Map<String, Object> msg) {
        log.info("文章分享收到消息，msg={}",msg);
        String userId = msg.get("userId").toString();
        if (StringUtil.isBlank(userId)) {
            return;
        }
        log.info("{}用户分享文章返积分",userId);
        RewardPointsReq req = new RewardPointsReq();
        req.setUserId(userId);
        req.setIsAccountType(ISAccountType.BASE_JIFEN.getCode());
        req.setOutTradeNo(UUID.randomUUID().toString().replace("-",""));
        req.setChannel(ISChannelType.FIRST_SHARE.getCode());
        ISUserBehaviorResult res = userBehaviorService.rewardPoints(req);
        ServiceResultUtil.checkResult(res);
    }

    @Override
    IntegralBusinessFlags getFlag() {
        return IntegralBusinessFlags.SHARE;
    }
}
